package com.fenghuajueli.idiomppp.widget;

import android.app.Activity;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;

import com.fenghuajueli.libbasecoreui.listener.OnBaseClick;

public class BackUpImageView extends AppCompatImageView implements View.OnClickListener {

    private OnBaseClick<Integer> mIOnBaseClick;

    public BackUpImageView(Context context) {
        super(context);
        init();
    }

    public BackUpImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public BackUpImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }


    private void init() {
        setOnClickListener(this);
    }


    public void setIOnBaseClick(OnBaseClick<Integer> IOnBaseClick) {
        this.mIOnBaseClick = IOnBaseClick;
    }

    @Override
    public void onClick(View view) {
        try {
            if (mIOnBaseClick != null) {
                mIOnBaseClick.onClick(view.getId());
            } else {
                ((Activity) getContext()).finish();
            }
        } catch (Exception e) {

        }
    }
}
